<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>DataTable | YiChangKong For Blog</title><meta name="keywords" content="技术文档"><meta name="author" content="伊长空"><meta name="copyright" content="伊长空"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><meta name="description" content="1.首先需要引用下面两个文件12 &lt;link rel&#x3D;&quot;stylesheet&quot; href&#x3D;&quot;https:&#x2F;&#x2F;cdn.datatables.net&#x2F;1.10.16&#x2F;css&#x2F;jquery.dataTables.min.css&quot; &#x2F;&gt;\&gt;  2.DataTable支持的数据类型https:&#x2F;&#x2F;www.datatables.net&#x2F;manual&#x2F;">
<meta property="og:type" content="article">
<meta property="og:title" content="DataTable">
<meta property="og:url" content="https://yichangkong.gitee.io/2020/11/25/DataTable/index.html">
<meta property="og:site_name" content="YiChangKong For Blog">
<meta property="og:description" content="1.首先需要引用下面两个文件12 &lt;link rel&#x3D;&quot;stylesheet&quot; href&#x3D;&quot;https:&#x2F;&#x2F;cdn.datatables.net&#x2F;1.10.16&#x2F;css&#x2F;jquery.dataTables.min.css&quot; &#x2F;&gt;\&gt;  2.DataTable支持的数据类型https:&#x2F;&#x2F;www.datatables.net&#x2F;manual&#x2F;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201125100521.png">
<meta property="article:published_time" content="2020-11-25T01:45:41.000Z">
<meta property="article:modified_time" content="2022-04-28T16:17:11.571Z">
<meta property="article:author" content="伊长空">
<meta property="article:tag" content="技术文档">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201125100521.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://yichangkong.gitee.io/2020/11/25/DataTable/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css"><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  ClickShowText: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  justifiedGallery: {
    js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
    css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
};

var saveToLocal = {
  set: function setWithExpiry(key, value, ttl) {
    const now = new Date()
    const expiryDay = ttl * 86400000
    const item = {
      value: value,
      expiry: now.getTime() + expiryDay,
    }
    localStorage.setItem(key, JSON.stringify(item))
  },

  get: function getWithExpiry(key) {
    const itemStr = localStorage.getItem(key)

    if (!itemStr) {
      return undefined
    }
    const item = JSON.parse(itemStr)
    const now = new Date()

    if (now.getTime() > item.expiry) {
      localStorage.removeItem(key)
      return undefined
    }
    return item.value
  }
}</script><script id="config_change">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-04-29 00:17:11'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(function () {  window.activateDarkMode = function () {
    document.documentElement.setAttribute('data-theme', 'dark')
    if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
    }
  }
  window.activateLightMode = function () {
    document.documentElement.setAttribute('data-theme', 'light')
   if (document.querySelector('meta[name="theme-color"]') !== null) {
      document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
    }
  }
  const autoChangeMode = 'false'
  const t = saveToLocal.get('theme')
  if (autoChangeMode === '1') {
    const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
    const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
    const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
    const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified
    if (t === undefined) {
      if (isLightMode) activateLightMode()
      else if (isDarkMode) activateDarkMode()
      else if (isNotSpecified || hasNoSupport) {
        const now = new Date()
        const hour = now.getHours()
        const isNight = hour <= 6 || hour >= 18
        isNight ? activateDarkMode() : activateLightMode()
      }
      window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
        if (saveToLocal.get('theme') === undefined) {
          e.matches ? activateDarkMode() : activateLightMode()
        }
      })
    } else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else if (autoChangeMode === '2') {
    const now = new Date()
    const hour = now.getHours()
    const isNight = hour <= 6 || hour >= 18
    if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
    else if (t === 'light') activateLightMode()
    else activateDarkMode()
  } else {
    if (t === 'dark') activateDarkMode()
    else if (t === 'light') activateLightMode()
  }const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
   if (asideStatus === 'hide') {
     document.documentElement.classList.add('hide-aside')
   } else {
     document.documentElement.classList.remove('hide-aside')
   }
}})()</script><meta name="generator" content="Hexo 5.2.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20200417183933.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">45</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">45</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div></div></div></div><div id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(https://gitee.com/yichangkong/FigureBed/raw/master/img/20201125100521.png)"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">YiChangKong For Blog</a></span><span id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div></div><span class="close" id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></span></span></nav><div id="post-info"><h1 class="post-title">DataTable</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2020-11-25T01:45:41.000Z" title="发表于 2020-11-25 09:45:41">2020-11-25</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-04-28T16:17:11.571Z" title="更新于 2022-04-29 00:17:11">2022-04-29</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/frontend/">frontend</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/frontend/DataTable/">DataTable</a></span></div><div class="meta-secondline"> <span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p><img src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201125100521.png"></p>
<h1 id="1-首先需要引用下面两个文件"><a href="#1-首先需要引用下面两个文件" class="headerlink" title="1.首先需要引用下面两个文件"></a>1.首先需要引用下面两个文件</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"> &lt;link rel=<span class="string">&quot;stylesheet&quot;</span> href=<span class="string">&quot;https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css&quot;</span> /&gt;</span><br><span class="line">\&gt;</span><br></pre></td></tr></table></figure>

<h1 id="2-DataTable支持的数据类型"><a href="#2-DataTable支持的数据类型" class="headerlink" title="2.DataTable支持的数据类型"></a>2.DataTable支持的数据类型</h1><p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.datatables.net/manual/data/">https://www.datatables.net/manual/data/</a></p>
<h2 id="2-1-数组"><a href="#2-1-数组" class="headerlink" title="2.1 数组"></a>2.1 数组</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">vardata &#x3D; [</span><br><span class="line">    [</span><br><span class="line">        &quot;Tiger Nixon&quot;,</span><br><span class="line">        &quot;System Architect&quot;,</span><br><span class="line">        &quot;Edinburgh&quot;,</span><br><span class="line">        &quot;5421&quot;,</span><br><span class="line">        &quot;2011&#x2F;04&#x2F;25&quot;,</span><br><span class="line">        &quot;$3,120&quot;</span><br><span class="line">    ],</span><br><span class="line">    [</span><br><span class="line">        &quot;Garrett Winters&quot;,</span><br><span class="line">        &quot;Director&quot;,</span><br><span class="line">        &quot;Edinburgh&quot;,</span><br><span class="line">        &quot;8422&quot;,</span><br><span class="line">        &quot;2011&#x2F;07&#x2F;25&quot;,</span><br><span class="line">        &quot;$5,300&quot;</span><br><span class="line">    ]</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<h2 id="2-2-对象"><a href="#2-2-对象" class="headerlink" title="2.2 对象"></a>2.2 对象</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">[</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="string">&quot;name&quot;</span>:       <span class="string">&quot;Tiger Nixon&quot;</span>,</span><br><span class="line">        <span class="string">&quot;position&quot;</span>:   <span class="string">&quot;System Architect&quot;</span>,</span><br><span class="line">        <span class="string">&quot;salary&quot;</span>:     <span class="string">&quot;$3,120&quot;</span>,</span><br><span class="line">        <span class="string">&quot;start_date&quot;</span>: <span class="string">&quot;2011/04/25&quot;</span>,</span><br><span class="line">        <span class="string">&quot;office&quot;</span>:     <span class="string">&quot;Edinburgh&quot;</span>,</span><br><span class="line">        <span class="string">&quot;extn&quot;</span>:       <span class="string">&quot;5421&quot;</span></span><br><span class="line">    &#125;,</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="string">&quot;name&quot;</span>:       <span class="string">&quot;Garrett Winters&quot;</span>,</span><br><span class="line">        <span class="string">&quot;position&quot;</span>:   <span class="string">&quot;Director&quot;</span>,</span><br><span class="line">        <span class="string">&quot;salary&quot;</span>:     <span class="string">&quot;$5,300&quot;</span>,</span><br><span class="line">        <span class="string">&quot;start_date&quot;</span>: <span class="string">&quot;2011/07/25&quot;</span>,</span><br><span class="line">        <span class="string">&quot;office&quot;</span>:     <span class="string">&quot;Edinburgh&quot;</span>,</span><br><span class="line">        <span class="string">&quot;extn&quot;</span>:       <span class="string">&quot;8422&quot;</span></span><br><span class="line">    &#125;</span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<h2 id="2-3-自定义实例（本质和2-2一样）"><a href="#2-3-自定义实例（本质和2-2一样）" class="headerlink" title="2.3 自定义实例（本质和2.2一样）"></a>2.3 自定义实例（本质和2.2一样）</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">functionEmployee ( name, position, salary, office ) &#123;</span><br><span class="line">    <span class="built_in">this</span>.name = name;</span><br><span class="line">    <span class="built_in">this</span>.position = position;</span><br><span class="line">    <span class="built_in">this</span>.salary = salary;</span><br><span class="line">    <span class="built_in">this</span>._office = office;</span><br><span class="line">    <span class="built_in">this</span>.office = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">        returnthis._office;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;;   </span><br><span class="line"></span><br><span class="line">$(<span class="string">&#x27;#example&#x27;</span>).DataTable( &#123;</span><br><span class="line">    data: [</span><br><span class="line">        newEmployee( <span class="string">&quot;Tiger Nixon&quot;</span>, <span class="string">&quot;System Architect&quot;</span>, <span class="string">&quot;$3,120&quot;</span>, <span class="string">&quot;Edinburgh&quot;</span>),</span><br><span class="line">        newEmployee( <span class="string">&quot;Garrett Winters&quot;</span>, <span class="string">&quot;Director&quot;</span>, <span class="string">&quot;$5,300&quot;</span>, <span class="string">&quot;Edinburgh&quot;</span>)</span><br><span class="line">    ],</span><br><span class="line">    columns: [</span><br><span class="line">        &#123; <span class="attr">data</span>: <span class="string">&#x27;name&#x27;</span>&#125;,</span><br><span class="line">        &#123; <span class="attr">data</span>: <span class="string">&#x27;salary&#x27;</span>&#125;,</span><br><span class="line">        &#123; <span class="attr">data</span>: <span class="string">&#x27;office&#x27;</span>&#125;,</span><br><span class="line">        &#123; <span class="attr">data</span>: <span class="string">&#x27;position&#x27;</span>&#125;</span><br><span class="line">    ]</span><br><span class="line">&#125; );</span><br></pre></td></tr></table></figure>

<h2 id="2-4-Datatable的数据来源"><a href="#2-4-Datatable的数据来源" class="headerlink" title="2.4 Datatable的数据来源"></a>2.4 Datatable的数据来源</h2><h3 id="1-DOM"><a href="#1-DOM" class="headerlink" title="1.DOM"></a>1.DOM</h3><p>如果没有指定data，ajax选项，则DataTable会将当前table的html标签上内容转换成对应的数据（Array数据形式）。</p>
<h3 id="2-Html5"><a href="#2-Html5" class="headerlink" title="2.Html5"></a>2.Html5</h3><p>Data-* 标签上可以指定不同的值，用于排序和查找，td内部标签的值对应当前单元格的数据。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">&lt;td data-search&#x3D;&quot;21st November 2016 21&#x2F;11&#x2F;2016&quot; data-order&#x3D;&quot;1479686400&quot;&gt;</span><br><span class="line">    21st November 2016</span><br><span class="line">&lt;&#x2F;td&gt;</span><br></pre></td></tr></table></figure>

<h3 id="3-javascript"><a href="#3-javascript" class="headerlink" title="3.javascript"></a>3.javascript</h3><p> 通过data配置，指定数据源。可以通过DataTables API row.add() row().remove()操作行数据。</p>
<h3 id="4-Ajax"><a href="#4-Ajax" class="headerlink" title="4.Ajax"></a>4.Ajax</h3><p> 通过服务器端分页的方式，取得数据。返回的数据只能是<strong>json数组或对象</strong>（上面的2.1和2.2）. </p>
<h1 id="3-有两种分页方式"><a href="#3-有两种分页方式" class="headerlink" title="3.有两种分页方式"></a>3.有两种分页方式</h1><h2 id="3-1-客户端分页"><a href="#3-1-客户端分页" class="headerlink" title="3.1 客户端分页"></a>3.1 客户端分页</h2><p>这种方式，代码最简单，整个数据量在10000条以内可以考虑。假设已经有了下面的table： </p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">&lt;table id=<span class="string">&quot;table1&quot;</span> <span class="class"><span class="keyword">class</span></span>=<span class="string">&quot;table table-condensed&quot;</span>&gt;</span><br><span class="line">    &lt;thead&gt;</span><br><span class="line">        &lt;tr&gt;</span><br><span class="line">            &lt;th&gt;ID&lt;/th&gt;</span><br><span class="line">            &lt;th&gt;Name&lt;/th&gt;</span><br><span class="line">            &lt;th&gt;Score&lt;/th&gt;</span><br><span class="line">        &lt;/tr&gt;</span><br><span class="line">    &lt;/thead&gt;</span><br><span class="line">    &lt;tbody&gt;</span><br><span class="line">        &lt;tr&gt;</span><br><span class="line">            &lt;td&gt;<span class="number">001</span>&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;zhang&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;<span class="number">98</span>&lt;/td&gt;</span><br><span class="line">        &lt;/tr&gt;</span><br><span class="line">        &lt;tr&gt;</span><br><span class="line">            &lt;td&gt;<span class="number">002</span>&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;wang&lt;/td&gt;</span><br><span class="line">            &lt;td&gt;<span class="number">99</span>&lt;/td&gt;</span><br><span class="line">        &lt;/tr&gt;</span><br><span class="line">    &lt;/tbody&gt;</span><br><span class="line">&lt;/table&gt;</span><br></pre></td></tr></table></figure>

<p> 简单调用一句话（使用默认设置），就可以使table具有排序，查找，分页的基本功能。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">$(<span class="string">&quot;#table1&quot;</span>).DataTable(&#123; &#125;);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>



<h2 id="3-2-服务器端分页"><a href="#3-2-服务器端分页" class="headerlink" title="3.2 服务器端分页"></a>3.2 服务器端分页</h2><p>这种方式针对大数据量的table（10万条以上），每次只读取当前的一页数据，分页在后台做。代码相对复杂，不过页面响应更快，服务器端的分页一般要求我们先定义thead表头，tbody可以不写。</p>
<h1 id="4-配置参数"><a href="#4-配置参数" class="headerlink" title="4.配置参数"></a>4.配置参数</h1><p>这些配置参数可以通过javascript进行设置，也可以直接用HTML5标签data-* 的方式写在table的标签中。</p>
<p>所有的配置选项：<a target="_blank" rel="noopener external nofollow noreferrer" href="https://www.datatables.net/reference/option/">https://www.datatables.net/reference/option/</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">       $(<span class="string">&quot;#table1&quot;</span>).DataTable(&#123;</span><br><span class="line">           <span class="comment">// 是否允许检索</span></span><br><span class="line">           <span class="string">&quot;searching&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 是否允许排序</span></span><br><span class="line">           <span class="string">&quot;ordering&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">           <span class="comment">// 初期排序列</span></span><br><span class="line">           <span class="comment">//&quot;order&quot;: [[0,&#x27;asc&#x27;],[1,&#x27;desc&#x27;]],</span></span><br><span class="line">           <span class="comment">// 是否显示情报 就是&quot;当前显示1/100记录&quot;这个信息</span></span><br><span class="line">           <span class="string">&quot;info&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 是否允许翻页，设成false，翻页按钮不显示</span></span><br><span class="line">           <span class="string">&quot;paging&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 水平滚动条</span></span><br><span class="line">           <span class="string">&quot;scrollX&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 垂直滚动条</span></span><br><span class="line">           <span class="string">&quot;scrollY&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 件数选择功能 默认true</span></span><br><span class="line">           <span class="string">&quot;lengthChange&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 件数选择下拉框内容</span></span><br><span class="line">           <span class="string">&quot;lengthMenu&quot;</span>: [<span class="number">10</span>, <span class="number">25</span>, <span class="number">50</span>, <span class="number">75</span>, <span class="number">100</span>],</span><br><span class="line">           <span class="comment">// 每页的初期件数 用户可以操作lengthMenu上的值覆盖</span></span><br><span class="line">           <span class="string">&quot;pageLength&quot;</span>: <span class="number">50</span>,</span><br><span class="line">           <span class="comment">//翻页按钮样式</span></span><br><span class="line">           <span class="comment">// numbers:数字</span></span><br><span class="line">           <span class="comment">// simple:前一页，后一页</span></span><br><span class="line">           <span class="comment">// simple_numbers:前一页，后一页，数字</span></span><br><span class="line">           <span class="comment">// full:第一页，前一页，后一页，最后页</span></span><br><span class="line">           <span class="comment">//full_numbers:第一页，前一页，后一页，最后页，数字</span></span><br><span class="line">           <span class="comment">//first_last_numbers:第一页，最后页，数字</span></span><br><span class="line">           <span class="string">&quot;pagingType&quot;</span>: <span class="string">&quot;full_numbers&quot;</span>,</span><br><span class="line">           <span class="comment">// 行样式应用 指定多个的话，第一行tr的class为strip1，第二行为strip2，第三行为strip3.</span></span><br><span class="line">           <span class="comment">// 第四行以后又开始从strip1循环。。。 如果想指定成斑马条状，这里的class必须指定为2个。</span></span><br><span class="line">           <span class="string">&quot;stripeClasses&quot;</span>: [<span class="string">&#x27;strip1&#x27;</span>, <span class="string">&#x27;strip2&#x27;</span>, <span class="string">&#x27;strip3&#x27;</span>],</span><br><span class="line">           <span class="comment">// 自动列宽</span></span><br><span class="line">           <span class="string">&quot;autoWidth&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">           <span class="comment">// 是否表示 &quot;processing&quot; 加载中的信息，这个信息可以修改</span></span><br><span class="line">           <span class="string">&quot;processing&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">           <span class="comment">// 每次创建是否销毁以前的DataTable,默认false</span></span><br><span class="line">           <span class="string">&quot;destroy&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">           <span class="comment">// 控制表格各种信息的表示位置（比较复杂） 默认:lfrtip</span></span><br><span class="line">           <span class="comment">// 具体参考：https://datatables.net/reference/option/dom</span></span><br><span class="line">           <span class="string">&quot;dom&quot;</span>: <span class="string">&#x27;lrtip&#x27;</span>,</span><br><span class="line">           <span class="string">&quot;language&quot;</span>: &#123;</span><br><span class="line">               <span class="string">&quot;processing&quot;</span>: <span class="string">&quot;DataTables is currently busy&quot;</span>,</span><br><span class="line">               <span class="comment">// 当前页显示多少条</span></span><br><span class="line">               <span class="string">&quot;lengthMenu&quot;</span>: <span class="string">&quot;Display _MENU_ records&quot;</span>,</span><br><span class="line">               <span class="comment">// _START_（当前页的第一条的序号） ,_END_（当前页的最后一条的序号）,_TOTAL_（筛选后的总件数）,</span></span><br><span class="line">               <span class="comment">// _MAX_(总件数),_PAGE_(当前页号),_PAGES_（总页数）</span></span><br><span class="line">               <span class="string">&quot;info&quot;</span>: <span class="string">&quot;Showing page _PAGE_ of _PAGES_&quot;</span>,</span><br><span class="line">               <span class="comment">// 没有数据的显示（可选），如果没指定，会用zeroRecords的内容</span></span><br><span class="line">               <span class="string">&quot;emptyTable&quot;</span>: <span class="string">&quot;No data available in table&quot;</span>,</span><br><span class="line">               <span class="comment">// 筛选后，没有数据的表示信息，注意emptyTable优先级更高</span></span><br><span class="line">               <span class="string">&quot;zeroRecords&quot;</span>: <span class="string">&quot;No records to display&quot;</span>,</span><br><span class="line">               <span class="comment">// 千分位的符号，只对显示有效，默认就是&quot;,&quot;  一般不要改写</span></span><br><span class="line">               <span class="comment">//&quot;thousands&quot;: &quot;&#x27;&quot;,</span></span><br><span class="line">               <span class="comment">// 小数点位的符号，对输入解析有影响，默认就是&quot;.&quot; 一般不要改写</span></span><br><span class="line">               <span class="comment">//&quot;decimal&quot;: &quot;-&quot;,</span></span><br><span class="line">               <span class="comment">// 翻页按钮文字控制</span></span><br><span class="line">               <span class="string">&quot;paginate&quot;</span>: &#123;</span><br><span class="line">                   <span class="string">&quot;first&quot;</span>: <span class="string">&quot;First page&quot;</span>,</span><br><span class="line">                   <span class="string">&quot;last&quot;</span>: <span class="string">&quot;Last page&quot;</span>,</span><br><span class="line">                   <span class="string">&quot;next&quot;</span>: <span class="string">&quot;Next page&quot;</span>,</span><br><span class="line">                   <span class="string">&quot;previous&quot;</span>: <span class="string">&quot;Previous page&quot;</span></span><br><span class="line">               &#125;,</span><br><span class="line">               <span class="comment">// Client-Side用，Server-Side不用这个属性</span></span><br><span class="line">               <span class="string">&quot;loadingRecords&quot;</span>: <span class="string">&quot;Please wait - loading...&quot;</span></span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">// 默认是false</span></span><br><span class="line">           <span class="comment">// 如果设为true，将只渲染当前也的html，速度会很快，但是通过API就访问不到所有页的数据，有利有弊</span></span><br><span class="line">           <span class="comment">//&quot;deferRender&quot;: false,</span></span><br><span class="line">           <span class="comment">// 服务器端处理方式</span></span><br><span class="line">           <span class="string">&quot;serverSide&quot;</span>: <span class="literal">true</span>,</span><br><span class="line"></span><br><span class="line">           <span class="comment">// ajax选项 可以直接简单指定成请求的文件</span></span><br><span class="line">           <span class="comment">//&quot;ajax&quot;: &quot;data.json&quot;,</span></span><br><span class="line">           <span class="comment">// 也可以用对象来配置，更加灵活</span></span><br><span class="line">           <span class="string">&quot;ajax&quot;</span>: &#123;</span><br><span class="line">               <span class="comment">// url可以直接指定远程的json文件，或是MVC的请求地址 /Controller/Action</span></span><br><span class="line">               url: <span class="string">&quot;data.json&quot;</span>,</span><br><span class="line">               type: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">               <span class="comment">// 传给服务器的数据，可以添加我们自己的查询参数</span></span><br><span class="line">               data: <span class="function"><span class="keyword">function</span> (<span class="params">param</span>) </span>&#123;</span><br><span class="line">                   param.opportunityNO = $(<span class="string">&#x27;#txtSearch&#x27;</span>).val();</span><br><span class="line">                   <span class="keyword">return</span> param;</span><br><span class="line">               &#125;,</span><br><span class="line">               <span class="comment">//用于处理服务器端返回的数据。 dataSrc是DataTable特有的</span></span><br><span class="line">               dataSrc: <span class="function"><span class="keyword">function</span> (<span class="params">myJson</span>) </span>&#123;</span><br><span class="line">                   <span class="keyword">if</span> (myJson.timeout) &#123;</span><br><span class="line">                       <span class="keyword">return</span> <span class="string">&quot;&quot;</span>;</span><br><span class="line">                   &#125;</span><br><span class="line">                   <span class="keyword">return</span> myJson;</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">//指定用于行ID的属性名 默认是：DT_RowId</span></span><br><span class="line">           <span class="string">&quot;rowId&quot;</span>: <span class="string">&#x27;staffId&#x27;</span>,</span><br><span class="line">           <span class="comment">// 列定义</span></span><br><span class="line">           <span class="string">&quot;columns&quot;</span>: [            </span><br><span class="line">           &#123;</span><br><span class="line">               <span class="comment">// data 可以是属性名，或嵌套属性（WORKTM1.ID）,数组ArrOne[,] 用中括号中的字符连接数组后返回。</span></span><br><span class="line">               <span class="string">&quot;data&quot;</span>: <span class="string">&quot;WORKTM1&quot;</span>,</span><br><span class="line">               <span class="comment">// 这里的class会应用到td上面</span></span><br><span class="line">               <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>,</span><br><span class="line">               <span class="comment">// 列宽</span></span><br><span class="line">               <span class="string">&quot;width&quot;</span>: <span class="number">40</span>,</span><br><span class="line">               <span class="comment">// 很灵活，描绘每个单元格</span></span><br><span class="line">               <span class="comment">// data：当前cell的data，这个data和type有关</span></span><br><span class="line">               <span class="comment">// type：filter,display,type,sort</span></span><br><span class="line">               <span class="comment">// row:当前行数据</span></span><br><span class="line">               <span class="comment">// https://datatables.net/reference/option/columns.render</span></span><br><span class="line">               <span class="string">&quot;render&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params">data, type, row, meta</span>) </span>&#123;</span><br><span class="line">                   <span class="keyword">return</span> type === <span class="string">&#x27;display&#x27;</span> &amp;&amp; data.length &gt; <span class="number">40</span> ?</span><br><span class="line">                   <span class="string">&#x27;&lt;span title=&quot;&#x27;</span> + data + <span class="string">&#x27;&quot;&gt;&#x27;</span> + data.substr(<span class="number">0</span>, <span class="number">38</span>) + <span class="string">&#x27;...&lt;/span&gt;&#x27;</span> : data;</span><br><span class="line"></span><br><span class="line">               &#125;,</span><br><span class="line">               <span class="comment">// 是否可排序 默认值：true</span></span><br><span class="line">               <span class="string">&quot;orderable&quot;</span>: <span class="literal">true</span>,</span><br><span class="line">               <span class="comment">// 指定当前列排序操作的时候，用哪一列（几列）的数据进行真正的排序（通常是隐藏的）</span></span><br><span class="line">               <span class="string">&quot;orderData&quot;</span>: [<span class="number">0</span>, <span class="number">1</span>],</span><br><span class="line">               <span class="comment">// 这个属性 和type属性相似，指定排序时候这一列该怎么转换数据,</span></span><br><span class="line">               <span class="comment">//需要用到其他的插件 详细： https://datatables.net/plug-ins/sorting/</span></span><br><span class="line">               <span class="string">&quot;orderDataType&quot;</span>: <span class="string">&quot;dom-text&quot;</span>,</span><br><span class="line">               <span class="comment">// 是否显示当前列 默认值：true</span></span><br><span class="line">               <span class="string">&quot;visible&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">               <span class="comment">// 是否允许搜索此列 默认值：true</span></span><br><span class="line">               <span class="string">&quot;searchable&quot;</span>: <span class="literal">false</span>,</span><br><span class="line">               <span class="comment">//这个属性仅Client-Side有效， Server-Side在服务器端排序 </span></span><br><span class="line">               <span class="comment">//主要用于排序和筛选，指定当前列作为什么类型进行解析</span></span><br><span class="line">               <span class="comment">//内置值：date，num，num-fmt，html-num，html-num-fmt，html，string</span></span><br><span class="line">               <span class="comment">// 还可以用其他插件提供的类型 ：详细： https://datatables.net/plug-ins/sorting/</span></span><br><span class="line">               <span class="comment">// 有html开头的，都会讲html标签先移除后进行数据处理</span></span><br><span class="line">               <span class="string">&quot;type&quot;</span>: <span class="string">&quot;html&quot;</span>,</span><br><span class="line">               <span class="comment">// 列头文字，如果没有指定thead，则会生成。如何指定了thead，则会覆盖当前列头文字</span></span><br><span class="line">               <span class="string">&quot;title&quot;</span>: <span class="string">&quot;My column title&quot;</span>,</span><br><span class="line">               <span class="comment">// defaultContent:默认值，属性值为null或undefined就会用这个值</span></span><br><span class="line">               <span class="string">&quot;defaultContent&quot;</span>: <span class="string">&quot;&lt;i&gt;Not set&lt;/i&gt;&quot;</span>,</span><br><span class="line">               <span class="comment">// 单元格类型：&quot;th&quot;,&quot;td&quot;</span></span><br><span class="line">               <span class="string">&quot;cellType&quot;</span> : <span class="string">&quot;td&quot;</span>,</span><br><span class="line">               <span class="comment">// 单元格创建完后的回调，可以作为render的补充</span></span><br><span class="line">               <span class="comment">// cell:TD的dom</span></span><br><span class="line">               <span class="comment">// cellData:原始的单元格数据，如何render中进行了格式化，用$(cell).html()来取格式化后的数据</span></span><br><span class="line">               <span class="comment">// rowData:行数据</span></span><br><span class="line">               <span class="comment">// row:行号</span></span><br><span class="line">               <span class="comment">// col:列号</span></span><br><span class="line">               <span class="string">&quot;createdCell&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params">cell, cellData, rowData, row, col</span>) </span>&#123;</span><br><span class="line">                   <span class="keyword">if</span> ( cellData &lt; <span class="number">1</span> ) &#123;</span><br><span class="line">                       $(td).css(<span class="string">&#x27;color&#x27;</span>, <span class="string">&#x27;red&#x27;</span>)</span><br><span class="line">                   &#125;</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;WORKTM2&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;WORKTM3&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;WORKTM4&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;RESTDAY1&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;RESTDAY2&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;RESTDAY3&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;RESTDAY4&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;,</span><br><span class="line">           &#123; <span class="string">&quot;data&quot;</span>: <span class="string">&quot;RESTDAY5&quot;</span>, <span class="string">&quot;className&quot;</span>: <span class="string">&quot;dt-body-right&quot;</span>, <span class="string">&quot;width&quot;</span>: <span class="number">40</span> &#125;</span><br><span class="line">           ],</span><br><span class="line">           <span class="comment">// 和上面的columns类似，columns可以定义的属性，都可以在这里定义，</span></span><br><span class="line">           <span class="comment">// 另外增加targets属性用于指定列范围（可以多列）</span></span><br><span class="line">           <span class="comment">// 优先级：上面的columns高于columnDefs</span></span><br><span class="line">           columnDefs: [</span><br><span class="line">           &#123;</span><br><span class="line">               targets: [<span class="number">0</span>, <span class="number">2</span>],</span><br><span class="line">               render: <span class="function"><span class="keyword">function</span> (<span class="params">data, type, row, meta</span>) </span>&#123;</span><br><span class="line">                   <span class="keyword">if</span> (type === <span class="string">&#x27;display&#x27;</span>) &#123;</span><br><span class="line">                       <span class="keyword">var</span> ctemp = $(<span class="string">&quot;.dayinfo&quot;</span>).children().eq(meta.col).attr(<span class="string">&quot;class&quot;</span>);</span><br><span class="line">                       <span class="keyword">var</span> cname = ctemp ? ctemp : <span class="string">&quot;&quot;</span>;</span><br><span class="line">                       <span class="keyword">var</span> readonly = $(<span class="string">&quot;.dayinfo&quot;</span>).children().eq(meta.col).attr(<span class="string">&quot;data-fixed&quot;</span>) == <span class="string">&quot;fixed&quot;</span> ? <span class="string">&quot;readonly&quot;</span> : <span class="string">&quot;&quot;</span>;</span><br><span class="line">                       <span class="keyword">return</span> <span class="string">&#x27;&lt;input type=&quot;input&quot; class=&quot;form-control dt-body-center &#x27;</span> + cname + <span class="string">&#x27;&quot; &#x27;</span> + readonly + <span class="string">&#x27; value=&quot;&#x27;</span> + data + <span class="string">&#x27;&quot;&gt;&#x27;</span>;</span><br><span class="line">                   &#125;</span><br><span class="line">                   <span class="keyword">return</span> data;</span><br><span class="line">               &#125;,</span><br><span class="line">           &#125;],</span><br><span class="line">           <span class="comment">// 每一行创建完调用的函数</span></span><br><span class="line">           <span class="string">&quot;createdRow&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params">row, data, dataIndex</span>) </span>&#123;</span><br><span class="line">               <span class="comment">// row : tr dom</span></span><br><span class="line">               <span class="comment">// data: row data</span></span><br><span class="line">               <span class="comment">// dataIndex:row data&#x27;s index</span></span><br><span class="line">               <span class="keyword">if</span> (data[<span class="number">4</span>] == <span class="string">&quot;A&quot;</span>) &#123;</span><br><span class="line">                   $(row).addClass(<span class="string">&#x27;important&#x27;</span>);</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">// 每一行被创建，但还没有被加载到document中，这个函数优先于createdRow</span></span><br><span class="line">           <span class="comment">// 个人觉得用createdRow更好</span></span><br><span class="line">           <span class="string">&quot;rowCallback&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params">row, data, index</span>) </span>&#123;</span><br><span class="line">               <span class="comment">// row : tr dom</span></span><br><span class="line">               <span class="comment">// data: row data</span></span><br><span class="line">               <span class="comment">// index:row data&#x27;s index</span></span><br><span class="line">               <span class="keyword">if</span> ( data[<span class="number">4</span>] == <span class="string">&quot;A&quot;</span> ) &#123;</span><br><span class="line">                   $(<span class="string">&#x27;td:eq(4)&#x27;</span>, row).html( <span class="string">&#x27;&lt;b&gt;A&lt;/b&gt;&#x27;</span> );</span><br><span class="line">               &#125;</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">//thead被描画后调用</span></span><br><span class="line">           <span class="string">&quot;headerCallback&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params">thead, data, start, end, display</span>) </span>&#123;</span><br><span class="line">               <span class="comment">//thead:dom， data:原始的datatable数据，display：当前显示排序好的datatable数据（有可能经过排序）</span></span><br><span class="line">               <span class="comment">// start end ：当前dispaly数据的开始结束序号</span></span><br><span class="line">               $(thead).find(<span class="string">&#x27;th&#x27;</span>).eq(<span class="number">0</span>).html( <span class="string">&#x27;Displaying &#x27;</span>+(end-start)+<span class="string">&#x27; records&#x27;</span> );</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">// tfoot被描画后调用，通常可用于计算合计值</span></span><br><span class="line">           <span class="string">&quot;footerCallback&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params">tfoot, data, start, end, display</span>) </span>&#123;</span><br><span class="line">               <span class="comment">//tfoot:dom， data:原始的datatable数据，display：当前显示排序好的datatable数据（有可能经过排序）</span></span><br><span class="line">               <span class="comment">// start end ：当前dispaly数据的开始结束序号</span></span><br><span class="line">               <span class="keyword">var</span> api = <span class="built_in">this</span>.api();</span><br><span class="line">               $( api.column( <span class="number">5</span> ).footer() ).html(</span><br><span class="line">                   api.column( <span class="number">5</span> ).data().reduce( <span class="function"><span class="keyword">function</span> (<span class="params"> a, b </span>) </span>&#123;</span><br><span class="line">                       <span class="keyword">return</span> a + b;</span><br><span class="line">                   &#125;, <span class="number">0</span> )</span><br><span class="line">               );</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">// 初始化，描画都已经完成，常用于ajax</span></span><br><span class="line">           <span class="string">&quot;initComplete&quot;</span>: <span class="function"><span class="keyword">function</span>(<span class="params"> settings, json </span>) </span>&#123;</span><br><span class="line">               $(<span class="string">&#x27;div.loading&#x27;</span>).remove();</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">// 每次DataTable描画后都要调用，调用这个函数时，table可能没有描画完成，</span></span><br><span class="line">           <span class="comment">// 所以不要在里面操作table的dom，要操作dom应放在initComplete</span></span><br><span class="line">           <span class="string">&quot;drawCallback&quot;</span>: <span class="function"><span class="keyword">function</span>(<span class="params"> settings </span>) </span>&#123;</span><br><span class="line">               <span class="keyword">var</span> api = <span class="built_in">this</span>.api();</span><br><span class="line"></span><br><span class="line">               <span class="comment">// Output the data for the visible rows to the browser&#x27;s console</span></span><br><span class="line">               <span class="built_in">console</span>.log( api.rows( &#123;<span class="attr">page</span>:<span class="string">&#x27;current&#x27;</span>&#125; ).data() );</span><br><span class="line">           &#125;,</span><br><span class="line">           <span class="comment">// 这个函数可以改写数字的格式化方式</span></span><br><span class="line">           <span class="comment">// 默认DataTable用 language.thousands来解析数字，“，”</span></span><br><span class="line">           <span class="string">&quot;formatNumber&quot;</span>: <span class="function"><span class="keyword">function</span> (<span class="params"> toFormat </span>) </span>&#123;</span><br><span class="line">               <span class="keyword">return</span> toFormat.toString().replace(</span><br><span class="line">                 /\B(?=(\d&#123;<span class="number">3</span>&#125;)+(?!\d))/g, <span class="string">&quot;&#x27;&quot;</span></span><br><span class="line">               );</span><br><span class="line">           &#125;</span><br><span class="line">       &#125;);</span><br><span class="line">   &#125;);</span><br></pre></td></tr></table></figure>

<h1 id="5-服务器端的参数"><a href="#5-服务器端的参数" class="headerlink" title="5.服务器端的参数"></a>5.服务器端的参数</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 发送到服务器端的数据</span></span><br><span class="line"><span class="comment">// draw：计数器，返回数据的时候用这个值设定</span></span><br><span class="line"><span class="comment">// start:开始记录（0 besed index）</span></span><br><span class="line"><span class="comment">// length:每页条数</span></span><br><span class="line"><span class="comment">// search[value]：检索文字</span></span><br><span class="line"><span class="comment">// order[i][column]：int 排序列的序号 例如：2，代表第3列排序 i代表有几个排序，一个的话服务器端这样写“order[0][column]”</span></span><br><span class="line"><span class="comment">// order[i][dir]：排序的方式&quot;desc&quot;,&quot;asc&quot;</span></span><br><span class="line"><span class="comment">// 下面comuns中的i取值从0~columns.length，所有的columns信息都发送到了服务器</span></span><br><span class="line"><span class="comment">// columns[i][data]：columns上定义的data属性值</span></span><br><span class="line"><span class="comment">// columns[i][name]：columns上定义的name属性值</span></span><br><span class="line"><span class="comment">// columns[i][searchable]：列能不能检索</span></span><br><span class="line"><span class="comment">// columns[i][orderable]：列能不能排序</span></span><br><span class="line"><span class="comment">// columns[i][search][value]：列的检索值 string</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 服务器返回的数据</span></span><br><span class="line"><span class="comment">// draw：和Request的draw设定成一样的值</span></span><br><span class="line"><span class="comment">// recordsTotal：所有的总件数</span></span><br><span class="line"><span class="comment">// recordsFiltered：筛选后的总件数</span></span><br><span class="line"><span class="comment">// data：返回的数据</span></span><br><span class="line"><span class="comment">//   每一行数据上面，可以包含这几个可选项</span></span><br><span class="line"><span class="comment">//   DT_RowId：加在行上的ID值</span></span><br><span class="line"><span class="comment">//   DT_RowClass：加在行上的Class</span></span><br><span class="line"><span class="comment">//   DT_RowData：加在行上的额外数据（object）</span></span><br><span class="line"><span class="comment">//   DT_RowAttr：加在行上的属性（object）</span></span><br><span class="line"><span class="comment">// error:如果有错误，就设定这个值，没有错误，不要包含这个值</span></span><br></pre></td></tr></table></figure>

<p>例子：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">using System;</span><br><span class="line">using System.Collections.Generic;</span><br><span class="line">using System.Linq;</span><br><span class="line">using System.Web;</span><br><span class="line">using System.Web.UI;</span><br><span class="line">using System.Web.UI.WebControls;</span><br><span class="line">using System.Data;</span><br><span class="line">using System.Configuration;</span><br><span class="line">using AppBlock;</span><br><span class="line">using System.Data.SqlClient;</span><br><span class="line">using Newtonsoft.Json;</span><br><span class="line"></span><br><span class="line">namespace alfest.Ajax</span><br><span class="line">&#123;</span><br><span class="line">  public partial class Category : System.Web.UI.Page</span><br><span class="line">  &#123;</span><br><span class="line">    string mode, option, user, limit, start, searchKey, orderByColumn, orderByDir, estMstSrno, pnlsrno, draw, jsonString;</span><br><span class="line">    CommonClass cmnCls = <span class="keyword">new</span> CommonClass();</span><br><span class="line">    protected <span class="keyword">void</span> Page_Load(object sender, EventArgs e)</span><br><span class="line">    &#123;</span><br><span class="line">      mode = Request.QueryString[<span class="string">&quot;mode&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;mode&quot;</span>].ToString();</span><br><span class="line">      option = Request.QueryString[<span class="string">&quot;option&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;option&quot;</span>].ToString();</span><br><span class="line">      limit = Request.QueryString[<span class="string">&quot;length&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;length&quot;</span>].ToString();</span><br><span class="line">      start = Request.QueryString[<span class="string">&quot;start&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;start&quot;</span>].ToString();</span><br><span class="line">      user = Request.QueryString[<span class="string">&quot;user&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;user&quot;</span>].ToString();</span><br><span class="line">      searchKey = Request.QueryString[<span class="string">&quot;search[value]&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;search[value]&quot;</span>].ToString();</span><br><span class="line">      orderByColumn = Request.QueryString[<span class="string">&quot;order[0][column]&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;order[0][column]&quot;</span>].ToString();</span><br><span class="line">      orderByDir = Request.QueryString[<span class="string">&quot;order[0][dir]&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;order[0][dir]&quot;</span>].ToString();</span><br><span class="line">      estMstSrno = Request.QueryString[<span class="string">&quot;estMstSrno&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;estMstSrno&quot;</span>].ToString();</span><br><span class="line">      pnlsrno = Request.QueryString[<span class="string">&quot;pnlsrno&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;pnlsrno&quot;</span>].ToString();</span><br><span class="line">      draw = Request.QueryString[<span class="string">&quot;draw&quot;</span>] == <span class="literal">null</span> ? <span class="string">&quot;&quot;</span> : Request.QueryString[<span class="string">&quot;draw&quot;</span>].ToString();</span><br><span class="line"></span><br><span class="line">      <span class="keyword">if</span> (option == <span class="string">&quot;GetAllAdminCategory&quot;</span>)</span><br><span class="line">      &#123;</span><br><span class="line"></span><br><span class="line">       <span class="comment">// Cls_Category CatgObj = new Cls_Category();</span></span><br><span class="line">       <span class="comment">// CatgObj.orderColumn = Convert.ToInt32(orderByColumn);</span></span><br><span class="line">       <span class="comment">// CatgObj.limit = Convert.ToInt32(limit);</span></span><br><span class="line">       <span class="comment">// CatgObj.orderDir = orderByDir;</span></span><br><span class="line">       <span class="comment">// CatgObj.start = Convert.ToInt32(start);</span></span><br><span class="line">       <span class="comment">// CatgObj.searchKey = searchKey;</span></span><br><span class="line">       <span class="comment">// CatgObj.option = &quot;GetAllAdminCategory&quot;;</span></span><br><span class="line"></span><br><span class="line">      <span class="comment">// or user your own method to get data (just fill the dataset)</span></span><br><span class="line"></span><br><span class="line">      <span class="comment">//  DataSet ds = cmnCls.PRC_category(CatgObj);</span></span><br><span class="line"></span><br><span class="line">        dynamic newtonresult = <span class="keyword">new</span></span><br><span class="line">          &#123;</span><br><span class="line">            status = <span class="string">&quot;success&quot;</span>,</span><br><span class="line">            draw = Convert.ToInt32(draw == <span class="string">&quot;&quot;</span> ? <span class="string">&quot;0&quot;</span> : draw),</span><br><span class="line">            recordsTotal = ds.Tables[<span class="number">1</span>].Rows[<span class="number">0</span>][<span class="number">0</span>],</span><br><span class="line">            recordsFiltered = ds.Tables[<span class="number">1</span>].Rows[<span class="number">0</span>][<span class="number">0</span>],</span><br><span class="line">            data = ds.Tables[<span class="number">0</span>]</span><br><span class="line">          &#125;;</span><br><span class="line">        jsonString = JsonConvert.SerializeObject(newtonresult);</span><br><span class="line"></span><br><span class="line">        Response.Clear();</span><br><span class="line">        Response.ContentType = <span class="string">&quot;application/json&quot;</span>;</span><br><span class="line">        Response.Write(jsonString);</span><br><span class="line"></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="6-DataTable常用事件"><a href="#6-DataTable常用事件" class="headerlink" title="6.DataTable常用事件"></a>6.DataTable常用事件</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//常用事件</span></span><br><span class="line"><span class="comment">// init：初始化和数据都加载完成，和 initComplete配置等价</span></span><br><span class="line">$(<span class="string">&#x27;#example&#x27;</span>)</span><br><span class="line">.on(<span class="string">&#x27;init.dt&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(<span class="string">&#x27;Table initialisation complete: &#x27;</span> + <span class="keyword">new</span> <span class="built_in">Date</span>().getTime());</span><br><span class="line">&#125;)</span><br><span class="line">.dataTable();</span><br><span class="line"></span><br><span class="line"><span class="comment">// error：处理数据出错 errMode必须为“none”，才会触发error事件</span></span><br><span class="line">$.fn.dataTable.ext.errMode = <span class="string">&#x27;none&#x27;</span>; <span class="comment">// alert,throw,none, a function</span></span><br><span class="line">$(<span class="string">&#x27;#example&#x27;</span>)</span><br><span class="line">    .on(<span class="string">&#x27;error.dt&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">e, settings, techNote, message</span>) </span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(<span class="string">&#x27;An error has been reported by DataTables: &#x27;</span>, message);</span><br><span class="line">    &#125;)</span><br><span class="line">    .DataTable();</span><br><span class="line"></span><br><span class="line"><span class="comment">// xhr：ajax加载数据完成后调用，这时数据并没有被描画，等价于 ajax.dataSrc</span></span><br><span class="line">$(<span class="string">&#x27;#example&#x27;</span>)</span><br><span class="line">.on(<span class="string">&#x27;xhr.dt&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">e, settings, json, xhr</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>, ien = json.aaData.length ; i &lt; ien ; i++) &#123;</span><br><span class="line">        json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// Note no return - manipulate the data directly in the JSON object.</span></span><br><span class="line">&#125;)</span><br><span class="line">.dataTable(&#123;</span><br><span class="line">    ajax: <span class="string">&quot;data.json&quot;</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h1 id="7-Datatable常用Api"><a href="#7-Datatable常用Api" class="headerlink" title="7.Datatable常用Api"></a>7.Datatable常用Api</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"> <span class="comment">//全部参考 https://datatables.net/reference/api/</span></span><br><span class="line"> <span class="comment">// 1，获取API的方式</span></span><br><span class="line"> <span class="comment">// 注意 $(selector).dataTable()得到的是table的jquery对象</span></span><br><span class="line"> <span class="comment">// 而api对象只能通过：api.$(select) 返回查找到的jquery对象。</span></span><br><span class="line"> $(selector).DataTable();</span><br><span class="line"> $(selector).dataTable().api();</span><br><span class="line"> <span class="keyword">new</span> $.fn.dataTable.Api(selector);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 2，得到一个api对象</span></span><br><span class="line"> <span class="keyword">var</span> table = $(<span class="string">&#x27;#example&#x27;</span>).DataTable();</span><br><span class="line"></span><br><span class="line"> <span class="comment">//3，描画 draw( [paging] ) 取值：true 全部重画，false 全部重画（保持当前的页面），</span></span><br><span class="line"><span class="comment">// &quot;page&quot; 不重取数据，只描画当前页</span></span><br><span class="line"> $(<span class="string">&#x27;#myFilter&#x27;</span>).on(<span class="string">&#x27;keyup&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">     table.search(<span class="built_in">this</span>.value).draw();</span><br><span class="line"> &#125;);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// Sort by column 1 and then re-draw</span></span><br><span class="line"> table.order([[<span class="number">1</span>, <span class="string">&#x27;asc&#x27;</span>]]).draw(<span class="literal">false</span>);</span><br><span class="line"> table.page(<span class="string">&#x27;next&#x27;</span>).draw(<span class="string">&#x27;page&#x27;</span>);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// data() 获取全表数据</span></span><br><span class="line"> <span class="comment">// Increment a counter for each row</span></span><br><span class="line"> table.data().each(<span class="function"><span class="keyword">function</span> (<span class="params">d</span>) </span>&#123;</span><br><span class="line">     d.counter++;</span><br><span class="line"> &#125;);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 4，column().data() 获取列数据</span></span><br><span class="line"> <span class="comment">// cloumn的第一个参数 可以是序号，或jquery支持的选择器</span></span><br><span class="line"> <span class="comment">// cloumn的第二个参数 是一个 selector-modifier  对象，取值如下</span></span><br><span class="line"> <span class="comment">//&#123;</span></span><br><span class="line"> <span class="comment">//    // DataTables core</span></span><br><span class="line"> <span class="comment">//    order:  &#x27;current&#x27;,  // &#x27;current&#x27;, &#x27;applied&#x27;, &#x27;index&#x27;,  &#x27;original&#x27;</span></span><br><span class="line"> <span class="comment">//    page:   &#x27;all&#x27;,      // &#x27;all&#x27;,     &#x27;current&#x27;</span></span><br><span class="line"> <span class="comment">//    search: &#x27;none&#x27;,     // &#x27;none&#x27;,    &#x27;applied&#x27;, &#x27;removed&#x27;</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//    // Extension - KeyTable (v2.1+) - cells only</span></span><br><span class="line"> <span class="comment">//    focused: undefined, // true, false, undefined</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">//    // Extension - Select (v1.0+)</span></span><br><span class="line"> <span class="comment">//    selected: undefined // true, false, undefined</span></span><br><span class="line"> <span class="comment">//&#125;</span></span><br><span class="line"> table.column(<span class="number">3</span>, &#123; <span class="attr">order</span>: <span class="string">&#x27;current&#x27;</span> &#125;).data();</span><br><span class="line"></span><br><span class="line"> <span class="comment">//5，row().data() 获取行数据</span></span><br><span class="line"> $(<span class="string">&#x27;#example tbody&#x27;</span>).on(<span class="string">&#x27;click&#x27;</span>, <span class="string">&#x27;tr&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">     <span class="built_in">console</span>.log(table.row(<span class="built_in">this</span>).data());</span><br><span class="line"> &#125;);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 6，row().node() 获取行dom对象</span></span><br><span class="line"> $(table.row(<span class="string">&#x27;#row-4&#x27;</span>).node()).addClass(<span class="string">&#x27;ready&#x27;</span>);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 7，row().remove(); 删除当前行</span></span><br><span class="line"> table.row(<span class="string">&#x27;#row-4&#x27;</span>).remove();</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 8， row.add() 加一行数据</span></span><br><span class="line"> <span class="comment">// rows.add() 加多行数据</span></span><br><span class="line"> table.row.add(&#123;<span class="attr">id</span>:<span class="string">&quot;1&quot;</span>,<span class="attr">name</span>:<span class="string">&quot;li&quot;</span>&#125;);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 9， table().body() 获取tbody dom 对象 </span></span><br><span class="line"> <span class="comment">// table().header() 获取theader dom 对象 </span></span><br><span class="line"> <span class="comment">// table().footer() 获取tfooter dom 对象 </span></span><br><span class="line"> <span class="comment">// table().node() 获取table dom 对象 </span></span><br><span class="line"> $(table.table().footer()).addClass(<span class="string">&#x27;highlight&#x27;</span>);</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 10，destroy() 销毁table true：连同html一起销毁</span></span><br><span class="line"> table.destroy(<span class="literal">false</span>)</span><br><span class="line"></span><br><span class="line"> <span class="comment">// 11，on 绑定table的事件</span></span><br><span class="line"> table.on(<span class="string">&#x27;xhr&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params">e, settings, json</span>) </span>&#123;</span><br><span class="line">     <span class="built_in">console</span>.log(<span class="string">&#x27;Ajax event occurred. Returned data: &#x27;</span>, json);</span><br><span class="line"> &#125;);</span><br><span class="line"> <span class="comment">// 12，page.len(10) 设置一页显示的条数</span></span><br><span class="line"> $(<span class="string">&#x27;#_10&#x27;</span>).on(<span class="string">&#x27;click&#x27;</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">     table.page.len(<span class="number">10</span>).draw();</span><br><span class="line"> &#125;);</span><br></pre></td></tr></table></figure>

<h1 id="8-其他"><a href="#8-其他" class="headerlink" title="8.其他"></a>8.其他</h1><h2 id="8-1-重新加载数据"><a href="#8-1-重新加载数据" class="headerlink" title="8.1  重新加载数据"></a>8.1  重新加载数据</h2><p>第二个参数为false的话，会保持当前的选中页。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vartable = $(<span class="string">&#x27;#example&#x27;</span>).DataTable();</span><br><span class="line"></span><br><span class="line">table.ajax.reload( <span class="function"><span class="keyword">function</span>(<span class="params"> json </span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    $(<span class="string">&#x27;#myInput&#x27;</span>).val( json.lastInput );</span><br><span class="line"></span><br><span class="line">&#125; , <span class="literal">true</span>);</span><br></pre></td></tr></table></figure>

<p>8.2 改变url，再加载 </p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">table.ajax.url( <span class="string">&#x27;newData.json&#x27;</span>).load();</span><br></pre></td></tr></table></figure>

<p>8.3 获取服务器返回的json数据</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">vartable = $(<span class="string">&#x27;#example&#x27;</span>).DataTable();</span><br><span class="line"></span><br><span class="line">table.on( <span class="string">&#x27;xhr&#x27;</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">    varjson = table.ajax.json();</span><br><span class="line"></span><br><span class="line">    alert( json.data.length +<span class="string">&#x27; row(s) were loaded&#x27;</span>);</span><br><span class="line"></span><br><span class="line">&#125; );</span><br></pre></td></tr></table></figure>

<h1 id="9-转载"><a href="#9-转载" class="headerlink" title="9.转载"></a>9.转载</h1><blockquote>
<p>1.<a target="_blank" rel="noopener external nofollow noreferrer" href="https://blog.csdn.net/qq_39949109/article/details/80406130">Datatable</a></p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined" rel="external nofollow noreferrer">伊长空</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://yichangkong.gitee.io/2020/11/25/DataTable/">https://yichangkong.gitee.io/2020/11/25/DataTable/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://yichangkong.gitee.io" target="_blank">YiChangKong For Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/%E6%8A%80%E6%9C%AF%E6%96%87%E6%A1%A3/">技术文档</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201125100521.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2020/12/12/SSM%E6%9E%B6%E6%9E%84%E4%B8%8B%E7%9A%84Cors%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98/"><img class="prev-cover" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201213132701.png" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">SSM架构下的Cors跨域问题</div></div></a></div><div class="next-post pull-right"><a href="/2020/11/14/The%20Key%20To%20Accelerating%20Your%20Coding%20Skills/"><img class="next-cover" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20200923232742.png" onerror="onerror=null;src='/img/404.jpg'"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">The Key To Accelerating Your Coding Skills</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2020/07/29/Git Command Line/" title="Git Command Line"><img class="cover" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201123192653.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-07-29</div><div class="title">Git Command Line</div></div></a></div><div><a href="/2020/01/28/H5 Overview/" title="H5 Overview"><img class="cover" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201122213711.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-01-28</div><div class="title">H5 Overview</div></div></a></div><div><a href="/2020/07/04/HashTable/" title="HashTable"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-07-04</div><div class="title">HashTable</div></div></a></div><div><a href="/2020/04/29/Redis命令行/" title="Redis命令行"><img class="cover" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20200429161847.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-04-29</div><div class="title">Redis命令行</div></div></a></div><div><a href="/2020/09/04/Synchronized in Java/" title="Synchronized in Java"><img class="cover" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2020-09-04</div><div class="title">Synchronized in Java</div></div></a></div><div><a href="/2019/11/25/UML Overview/" title="UML Overview"><img class="cover" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201122213024.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-25</div><div class="title">UML Overview</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside_content" id="aside_content"><div class="card-widget card-info"><div class="card-content"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20200417183933.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">伊长空</div><div class="author-info__description">空气越稀薄 、风景越广阔</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">45</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">9</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">45</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/CodeSnakes"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/yichangkong" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:changkongyi@gmail.com" rel="external nofollow noreferrer" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div></div><div class="card-widget card-announcement"><div class="card-content"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">繁华落尽一场空 ：风往尘香花已尽 <br> 		<div class="is-center"> 欢迎访问 <br> <a class="bookmark button--primary" id="bookmark-it" href="https://jq.qq.com/?_wv=1027&amp;k=rCby8DjL" rel="external nofollow noreferrer" title="" target="_self"><i aria-hidden="true"> </i><span>Join QQ Group 👍</span></a></div></div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="card-content"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E9%A6%96%E5%85%88%E9%9C%80%E8%A6%81%E5%BC%95%E7%94%A8%E4%B8%8B%E9%9D%A2%E4%B8%A4%E4%B8%AA%E6%96%87%E4%BB%B6"><span class="toc-number">1.</span> <span class="toc-text">1.首先需要引用下面两个文件</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-DataTable%E6%94%AF%E6%8C%81%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">2.</span> <span class="toc-text">2.DataTable支持的数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-%E6%95%B0%E7%BB%84"><span class="toc-number">2.1.</span> <span class="toc-text">2.1 数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-%E5%AF%B9%E8%B1%A1"><span class="toc-number">2.2.</span> <span class="toc-text">2.2 对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-3-%E8%87%AA%E5%AE%9A%E4%B9%89%E5%AE%9E%E4%BE%8B%EF%BC%88%E6%9C%AC%E8%B4%A8%E5%92%8C2-2%E4%B8%80%E6%A0%B7%EF%BC%89"><span class="toc-number">2.3.</span> <span class="toc-text">2.3 自定义实例（本质和2.2一样）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-4-Datatable%E7%9A%84%E6%95%B0%E6%8D%AE%E6%9D%A5%E6%BA%90"><span class="toc-number">2.4.</span> <span class="toc-text">2.4 Datatable的数据来源</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-DOM"><span class="toc-number">2.4.1.</span> <span class="toc-text">1.DOM</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-Html5"><span class="toc-number">2.4.2.</span> <span class="toc-text">2.Html5</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-javascript"><span class="toc-number">2.4.3.</span> <span class="toc-text">3.javascript</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-Ajax"><span class="toc-number">2.4.4.</span> <span class="toc-text">4.Ajax</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-%E6%9C%89%E4%B8%A4%E7%A7%8D%E5%88%86%E9%A1%B5%E6%96%B9%E5%BC%8F"><span class="toc-number">3.</span> <span class="toc-text">3.有两种分页方式</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#3-1-%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%88%86%E9%A1%B5"><span class="toc-number">3.1.</span> <span class="toc-text">3.1 客户端分页</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-2-%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF%E5%88%86%E9%A1%B5"><span class="toc-number">3.2.</span> <span class="toc-text">3.2 服务器端分页</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0"><span class="toc-number">4.</span> <span class="toc-text">4.配置参数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF%E7%9A%84%E5%8F%82%E6%95%B0"><span class="toc-number">5.</span> <span class="toc-text">5.服务器端的参数</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#6-DataTable%E5%B8%B8%E7%94%A8%E4%BA%8B%E4%BB%B6"><span class="toc-number">6.</span> <span class="toc-text">6.DataTable常用事件</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#7-Datatable%E5%B8%B8%E7%94%A8Api"><span class="toc-number">7.</span> <span class="toc-text">7.Datatable常用Api</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#8-%E5%85%B6%E4%BB%96"><span class="toc-number">8.</span> <span class="toc-text">8.其他</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#8-1-%E9%87%8D%E6%96%B0%E5%8A%A0%E8%BD%BD%E6%95%B0%E6%8D%AE"><span class="toc-number">8.1.</span> <span class="toc-text">8.1  重新加载数据</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#9-%E8%BD%AC%E8%BD%BD"><span class="toc-number">9.</span> <span class="toc-text">9.转载</span></a></li></ol></div></div></div><div class="card-widget card-recent-post"><div class="card-content"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/04/28/JOIN-Clause/" title="JOIN_Clause"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JOIN_Clause"/></a><div class="content"><a class="title" href="/2022/04/28/JOIN-Clause/" title="JOIN_Clause">JOIN_Clause</a><time datetime="2022-04-28T15:42:04.000Z" title="发表于 2022-04-28 23:42:04">2022-04-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/24/Vim%E9%94%AE%E4%BD%8D%E5%9B%BE/" title="Vim键位图"><img src="https://gitee.com/yichangkong/FigureBed/raw/master/img/vi-vim-cheat-sheet-sch.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vim键位图"/></a><div class="content"><a class="title" href="/2022/03/24/Vim%E9%94%AE%E4%BD%8D%E5%9B%BE/" title="Vim键位图">Vim键位图</a><time datetime="2022-03-24T03:32:15.000Z" title="发表于 2022-03-24 11:32:15">2022-03-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/12/requirejs%20Overview/" title="RequireJs Overview"><img src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="RequireJs Overview"/></a><div class="content"><a class="title" href="/2021/01/12/requirejs%20Overview/" title="RequireJs Overview">RequireJs Overview</a><time datetime="2021-01-12T02:43:34.000Z" title="发表于 2021-01-12 10:43:34">2021-01-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/12/12/SSM%E6%9E%B6%E6%9E%84%E4%B8%8B%E7%9A%84Cors%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98/" title="SSM架构下的Cors跨域问题"><img src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201213132701.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="SSM架构下的Cors跨域问题"/></a><div class="content"><a class="title" href="/2020/12/12/SSM%E6%9E%B6%E6%9E%84%E4%B8%8B%E7%9A%84Cors%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98/" title="SSM架构下的Cors跨域问题">SSM架构下的Cors跨域问题</a><time datetime="2020-12-12T13:13:28.000Z" title="发表于 2020-12-12 21:13:28">2020-12-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2020/11/25/DataTable/" title="DataTable"><img src="https://gitee.com/yichangkong/FigureBed/raw/master/img/20201125100521.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="DataTable"/></a><div class="content"><a class="title" href="/2020/11/25/DataTable/" title="DataTable">DataTable</a><time datetime="2020-11-25T01:45:41.000Z" title="发表于 2020-11-25 09:45:41">2020-11-25</time></div></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By 伊长空</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    let initData = {
      el: '#vcomment',
      appId: 'xuXblFdHlR0fcnQsdkLwkqvG-gzGzoHsz',
      appKey: 'ac3XS1leXcL95PWUhYV6gx0E',
      placeholder: 'Please leave your footprints',
      avatar: 'retro',
      meta: 'nick,mail'.split(','),
      pageSize: '10',
      lang: 'en',
      recordIP: false,
      serverURLs: '',
      emojiCDN: 'https://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/',
      emojiMaps: {"tv_doge":"6ea59c827c414b4a2955fe79e0f6fd3dcd515e24.png","tv_亲亲":"a8111ad55953ef5e3be3327ef94eb4a39d535d06.png","tv_偷笑":"bb690d4107620f1c15cff29509db529a73aee261.png","tv_再见":"180129b8ea851044ce71caf55cc8ce44bd4a4fc8.png","tv_冷漠":"b9cbc755c2b3ee43be07ca13de84e5b699a3f101.png","tv_发怒":"34ba3cd204d5b05fec70ce08fa9fa0dd612409ff.png","tv_发财":"34db290afd2963723c6eb3c4560667db7253a21a.png","tv_可爱":"9e55fd9b500ac4b96613539f1ce2f9499e314ed9.png","tv_吐血":"09dd16a7aa59b77baa1155d47484409624470c77.png","tv_呆":"fe1179ebaa191569b0d31cecafe7a2cd1c951c9d.png","tv_呕吐":"9f996894a39e282ccf5e66856af49483f81870f3.png","tv_困":"241ee304e44c0af029adceb294399391e4737ef2.png","tv_坏笑":"1f0b87f731a671079842116e0991c91c2c88645a.png","tv_大佬":"093c1e2c490161aca397afc45573c877cdead616.png","tv_大哭":"23269aeb35f99daee28dda129676f6e9ea87934f.png","tv_委屈":"d04dba7b5465779e9755d2ab6f0a897b9b33bb77.png","tv_害羞":"a37683fb5642fa3ddfc7f4e5525fd13e42a2bdb1.png","tv_尴尬":"7cfa62dafc59798a3d3fb262d421eeeff166cfa4.png","tv_微笑":"70dc5c7b56f93eb61bddba11e28fb1d18fddcd4c.png","tv_思考":"90cf159733e558137ed20aa04d09964436f618a1.png","tv_惊吓":"0d15c7e2ee58e935adc6a7193ee042388adc22af.png"},
      enableQQ: false,
      path: window.location.pathname,
    }

    if (true) { 
      initData.requiredFields= ('nick'.split(','))
    }
    
    if (false) {
      const otherData = false
      initData = Object.assign({}, initData, otherData)
    }
    
    const valine = new Valine(initData)
  }

  if (typeof Valine === 'function') initValine() 
  else $.getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js', initValine)
}

if ('Valine' === 'Valine' || !false) {
  if (false) btf.loadComment(document.querySelector('#vcomment'),loadValine)
  else setTimeout(() => loadValine(), 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><script src="https://cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script></div></body></html>